package com.demo.word2html.poi.support.office2007;

import org.apache.poi.xwpf.converter.core.IXWPFConverter;
import org.apache.poi.xwpf.converter.core.XWPFConverterException;
import org.apache.poi.xwpf.converter.xhtml.XHTMLConverter;
import org.apache.poi.xwpf.converter.xhtml.XHTMLOptions;
import org.apache.poi.xwpf.converter.xhtml.internal.XHTMLMapper;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.xml.sax.ContentHandler;

import java.io.IOException;

/**
 * 过滤页面中指定的字体
 *
 * @author fenggang.li
 * @create 2019-09-11 13:34
 */
public class ChangeFontXHTMLConverter extends XHTMLConverter {

    private static final ChangeFontXHTMLConverter INSTANCE = new ChangeFontXHTMLConverter();

    public static ChangeFontXHTMLConverter getInstance()
    {
        return INSTANCE;
    }

    public void convert(XWPFDocument document, ContentHandler contentHandler, XHTMLOptions options )
            throws XWPFConverterException, IOException
    {
        try
        {
            options = options != null ? options : XHTMLOptions.getDefault();
            XHTMLMapper mapper = new ChangeFontXHTMLMapper( document, contentHandler, options );
            mapper.start();
        }
        catch ( Exception e )
        {
            throw new XWPFConverterException( e );
        }
    }
}
